/**
 * @file elctron入口文件
 * @author fanxingguang@baidu.com
 */
// const superagent = require('superagent');
let cheerio = require('cheerio');
let http = require('http');
let util = require('./util');

let getHtml = url => {
    console.log('spider: ', url);
    let options = util.parseUrl(url);
    options.port = 80;
    return new Promise((resolve, reject) => {
        http.get(options, res => {
            let html = '';
            res.setEncoding('utf-8');
            res.on('data', chunk => {
                html += chunk;
            });
            res.on('end', () => {
                resolve(cheerio.load(html, {decodeEntities: false}));
            });
        }).on('error', function (err) {
            reject(err);
        });
    });
};
global.getHtml = getHtml;